/**
 * Created by scor on 15/9/2.
 */
var AV = require('leanengine');
var async = require('async');
var config = require('../config.js');
var CouponM = require('../models/coupon');
var log4js = require('log4js');
var logger = log4js.getLogger('normal');
module.exports = {
    getUserCouponsList:function(req,res,next){
        //res.json({a:1});
        var uid = req.AV.user.id;
        CouponM.getUserCouponsList(uid).then(function(obj){
            res.json(obj);
            logger.info(obj);
        }).catch(function(err){
            logger.error(err);
            res.json(err);
        });
    },
    getUserCouponsListConfirm:function(req,res,next){
        //res.json({a:1});
        var uid = req.AV.user.id;
        CouponM.getUserCouponsListConfirm(uid).then(function(obj){
            res.json(obj);
            logger.info(obj);
        }).catch(function(err){
            logger.error(err);
            res.json(err);
        });
    },
    getCouponCode:function(req,res,next){
        var uid = req.AV.user.id;
        var nickname = req.AV.user.get('nickname');
        var phone = req.AV.user.get('phone');
        var code=req.query.code;
        CouponM.getCouponCode(code,uid,nickname,phone).then(function(obj){
            res.json(obj);
            logger.info(obj);
        }).catch(function(err){
            logger.error(err);
            res.json(err);
        });
    }
};